/* Setup blank page controller */
(function () {
    'use strict';
    angular.module('module.login')
        .controller('LoginController', LoginController);

    LoginController.$inject = ['$rootScope', '$scope', 'settings', '$state', '$stateParams', 'jwtHelper', 'store'];

    function LoginController($rootScope, $scope, settings,$state,$stateParams,jwtHelper,store) {
        var vm = this;
        vm.form = {
            'loginName': '',
            'loginPwd': ''
        };

        vm.login = login;
        activate();

        return vm;

        function activate() {
            $scope.$on('$viewContentLoaded', function () {
                App.initAjax(); // initialize core components
            });
            settings.layout.pageLogin = true;
        }

        /**
         * 用户登录验证
         */
        function login() {
            console.log(vm.form.loginName);
            if(vm.form.loginName === 'admin')
            {
                settings.userRole = '0';
            }else if(vm.form.loginName === 'minjing'){
                settings.userRole = '1';
            }else if(vm.form.loginName === 'danwei'){
                settings.userRole = '2';
            }else if(vm.form.loginName === 'jigou'){
                settings.userRole = '3';
            }
            store.set('loginName',vm.form.loginName);
            store.set('userRole',settings.userRole);
            $state.go($stateParams.from);
        }
    }
})();
